package com.itheima.service.cmsService.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.cms.CmsSubject;
import com.itheima.mapper.cmsMapper.CmsSubjectMapper;
import com.itheima.service.cmsService.CmsSubjectService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: Ren
 * @date 2022 - 11 - 13 - 22:57
 * @Description: com.itheima.service.impl.cms
 * @version:1.0
 */
@DubboService
public class CmsSubjectServiceImpl implements CmsSubjectService {

    @Autowired
    CmsSubjectMapper cmsSubjectMapper;

    @Override
    public List<CmsSubject> findSubjectList() {

        return cmsSubjectMapper.selectList(null);
    }

    @Override
    public PageBeanVo findSubjectByPage(String keyword, Integer pageNum, Integer pageSize) {

        Page<CmsSubject> page = new Page<>(pageNum,pageSize);

        LambdaQueryWrapper<CmsSubject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(CmsSubject::getCategoryName,keyword);
        cmsSubjectMapper.selectPage(page,queryWrapper);
        Integer count = cmsSubjectMapper.selectCount(queryWrapper);

        return new PageBeanVo(pageNum,pageSize,count.longValue(),page.getRecords());
    }
}